package com.colin.aiyi.dao.ImpxUtils3_de;

import com.colin.aiyi.app.Constant;
import com.colin.aiyi.entity.response.BaseResponse;
import com.colin.aiyi.entity.response.UserInfoResponse;
import com.colin.aiyi.presenter.Interface.Callback;

import org.xutils.http.RequestParams;

import java.io.File;

/**
 * Created by hl on 2017/6/1.
 */
@Deprecated
public class ImpOther extends AbsServicexUtils {
    public static ImpOther impOther;
    int contentType=1;

    public static ImpOther getInstance() {
        if (impOther==null)
        {
            impOther=new ImpOther();
        }
        return impOther;
    }


    @Override
    public void onSuccess(String result) {
        super.onSuccess(result);
        if (contentType==6)
        {
            UserInfoResponse userInfo=gson.fromJson(result,UserInfoResponse.class);
            userInfo.setMsgType(contentType);
            sendMsgToView(userInfo);

        }else {
            BaseResponse baseResponse=gson.fromJson(result,BaseResponse.class);
            if (baseResponse!=null&&callback!=null)
            {
                baseResponse.setMsgType(contentType);
                callback.onSuccess(baseResponse);
               // sendMsgToView(baseResponse);
            }
        }

    }


   /* id	是	long	业务ID
    type	是	int	业务类型 1：一说 2：一句
    operType	是	boolean	true :收藏 false:取消收藏*/

    public void doLike(boolean operType,String  ... type){
        contentType=1;
        RequestParams parem=new RequestParams(Constant.LIKE_doLike);
        parem.addBodyParameter("id",type[0]);
        parem.addBodyParameter("type",type[1]);
        parem.addBodyParameter("operType",String.valueOf(operType));
        sendToServer(parem);
    }

    /*sayId	是	long	一说ID*/
    public void doWatch(String sayId){
        contentType=2;
        RequestParams parem=new RequestParams(Constant.SAY_watch);
        parem.addBodyParameter("sayId",sayId);
        sendToServer(parem);
    }

  /*  sayId	是	long	一说ID
    content	是	string	内容*/
    public void doCommint(String sayId,String content){
        contentType=3;
        RequestParams parem=new RequestParams(Constant.SAY_watch);
        parem.addBodyParameter("sayId",sayId);
        parem.addBodyParameter("content",content);
        sendToServer(parem);
    }

    public void doFeedBack(String content) {
        contentType=4;
        RequestParams parem=new RequestParams(Constant.feedback);
        parem.addBodyParameter("feedbackContent",content);
      //  parem.addBodyParameter("content",content);
        sendToServer(parem);
    }

    public void sendCodeforgetPw(Callback callback,String content) {
        super.getAllT(callback);
        contentType=5;
        RequestParams parems=new RequestParams(Constant.forgetPassword_sendCode);
        parems.addBodyParameter("telNo",content);
        parems.addBodyParameter("clientId",Constant.CLIENT_ID);
        parems.addBodyParameter("clientSecret",Constant.CLIENT_SECRET);
        sendToServer(parems,1);
    }
   /* telNo	是	string	手机号
    password	是	string	新密码
    code	否	string	验证码*/
    public void resetPW_forget(Callback callback,String telNo,String passwd,String vcode) {
        super.getAllT(callback);
        contentType=5;
        RequestParams parems=new RequestParams(Constant.forgetPassword_sendCode);
        parems.addBodyParameter("telNo",telNo);
        parems.addBodyParameter("password",passwd);
        parems.addBodyParameter("code",vcode);
        parems.addBodyParameter("clientId",Constant.CLIENT_ID);
        parems.addBodyParameter("clientSecret",Constant.CLIENT_SECRET);
        sendToServer(parems,1);
    }

 /*   telNo	是	string	手机号
    clientId	是	string	密码
    clientSecret	否	string	昵称*/
    public void sendCode_updatePW(Callback callback,String content) {
        super.getAllT(callback);
        contentType=5;
        RequestParams parems=new RequestParams(Constant.forgetPassword_sendCode);
        parems.addBodyParameter("telNo",content);
        parems.addBodyParameter("clientId",Constant.CLIENT_ID);
        parems.addBodyParameter("clientSecret",Constant.CLIENT_SECRET);
        sendToServer(parems,1);
    }

//   |newPassword |是 |string | 新密码 | |oldPassword |是 |string | 旧密码 |
    public void updatePassword(Callback callback,String telNo,String passwd,String oldPasswd,String vcode) {
        super.getAllT(callback);
        contentType=5;
        RequestParams parems=new RequestParams(Constant.forgetPassword_sendCode);
        parems.addBodyParameter("telNo",telNo);
        parems.addBodyParameter("newPassword",passwd);
        parems.addBodyParameter("oldPassword",oldPasswd);
        parems.addBodyParameter("code",vcode);
        parems.addBodyParameter("clientId",Constant.CLIENT_ID);
        parems.addBodyParameter("clientSecret",Constant.CLIENT_SECRET);
        sendToServer(parems,1);
    }

    /*得到我的个人信息*/
    public void getUserInfo(UserInfoResponse userInfo){
        super.getAllT(callback);
        if (userInfo!=null&&userInfo.getData()!=null)
        {
            contentType=6;
            RequestParams parems=new RequestParams(Constant.getUserInfo);
            parems.addBodyParameter("accessToken",userInfo.getData().getAccessToken());
            parems.addBodyParameter("clientId",Constant.CLIENT_ID);
            parems.addBodyParameter("clientSecret",Constant.CLIENT_SECRET);
            sendToServer(parems);
        }

    }
   /* 修改个人信息
    userName	否	String	用户名
    birthbay	否	long	生日
    sex	否	int	性别 1 男 2 女 3 未知
    isListen	否	boolean	true:3g4g下可收听
    isPush	否	boolean	true:推送
    cityId	否	Long	城市ID
    constellation	否	Long	星座
    imgFile	否	file	头像*/
    public void saveUserInfo(UserInfoResponse userInfo){
        super.getAllT(callback);
        contentType=7;
        RequestParams parems=new RequestParams(Constant.saveUserInfo);
        parems.addBodyParameter("clientId",Constant.CLIENT_ID);
        parems.addBodyParameter("clientSecret",Constant.CLIENT_SECRET);
        if (userInfo.getData().getUserName()!=null){
            parems.addBodyParameter("userName",userInfo.getData().getUserName());
        }
        if (userInfo.getData().getBirthbay()!=0){
            parems.addBodyParameter("birthbay",userInfo.getData().getBirthbay()+"");
        }
        if (userInfo.getData().getSex()!=0){
            parems.addBodyParameter("sex",userInfo.getData().getSex()+"");
        }
        parems.addBodyParameter("isListen", String.valueOf(userInfo.getData().isListen()));
        parems.addBodyParameter("isPush", String.valueOf(userInfo.getData().isPush()));
        if (userInfo.getData().getCityId()!=null){
            parems.addBodyParameter("cityId",userInfo.getData().getCityId());
        }
        if (userInfo.getData().getConstellation()!=null){
            parems.addBodyParameter("constellation",userInfo.getData().getConstellation());
        }
        if (userInfo.getData().getHeadUrl()!=null)
        {
            parems.setMultipart(true);
              //  上传文件方式 1
              //  params.uploadFile = new File("/sdcard/test.txt");
             //   上传文件方式 2
            parems.addBodyParameter("imgFile", new File(userInfo.getData().getHeadUrl()));
        }

        sendToServer(parems,1);
    }
}
